<?php namespace Common\Model;
use Hdphp\Model\Model;
class Log extends Model{
	protected $table='user';
	protected $auto=[
		['password','md5','function',3,3]
	];
	//执行自动验证
	protected $validate=[
		['username','required','用户名必填',3,3],
		['username','_user','用户名或密码输入不正确',3,3],
		['password','required','密码必填',3,3],
		['password','_pass','用户名或密码输入不正确',3,3],
		['code','required','验证码必填',3,3],
		['code','_code','验证码输入不正确',3,3]
	];
	public function _code(){
		$code=strtolower(Q('post.code'));
		
		if($code!=strtolower($_SESSION['code'])){
			return false;
		 }else{
		 	return true;
		 }
		
	}
	public function _user(){
		$username=Q('post.username');
		$data=$this->where("username='$username' or account='$username'")->find();
		if(!$data){
			return false;
		}
		return true;
	}
	public function _pass(){
		$username=Q('post.username');
		$data=$this->where("username='$username' or account='$username'")->find();
		$password=Q('post.password',0,'md5');
		if($data['password'] != $password){
			return false;
		}
		return true;
	}
	public function log(){
		if(!$this->create()) return false;
		return true;
	}
}
